﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Xml;
using System.Xml.Schema;

namespace FennecUI
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Directory.SetCurrentDirectory(Path.GetDirectoryName(Application.ExecutablePath));
            if (!Directory.Exists("Applets"))
            {
                Directory.CreateDirectory("Applets");
            }
            if (!File.Exists(Configuration.APPLET_CONFIGURATION_FILE))
            {
                MessageBox.Show("Error: Could not find AppletConfiguration.xml");
                return;
            }
            string[] args = Environment.GetCommandLineArgs();
            Environment.SetEnvironmentVariable("APPLETS_STORE",Directory.GetCurrentDirectory()+@"\Applets");
            if(args.Length>1 && File.Exists(args[1]) && Path.GetExtension(args[1])==".fpk"){
                if (PackageManager.InstallPackage(args[1]))
                {
                    MessageBox.Show("Installed Applet Successfully");
                }
                else
                {
                    MessageBox.Show("Error Occoured While Trying to Install Applet");
                }
            }
            else{
                Form.CheckForIllegalCrossThreadCalls = false;
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                mainForm = new MainForm();
                Application.Run(mainForm);
            }
        }

        public static MainForm mainForm;
    }
}
